// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Button Pillar Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 64 : TYPE_BUTTONPILLAR

// Function declarations
reserve function ButtonPillar_DebugDraw
reserve function ButtonPillar_DebugSpawn

// Static Values

// Tables

function ButtonPillar_DebugDraw
	DrawSprite(0)
end function


function ButtonPillar_DebugSpawn
	CreateTempObject(TypeName[Button Pillar], 0, object.xpos, object.ypos)
	object[tempObjectPos].value1 = object.ypos
end function


event ObjectMain
	switch object.state
	case 0
		if object[-1].propertyValue == 1
			object.state = 1
			object.priority = PRIORITY_ACTIVE
		end if
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_BOX, object.entityPos, -32, -56, 32, 56, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		next
		break
	case 1
		if object.value0 < 144
			object.value0 += 2
			foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
				BoxCollisionTest(C_BOX, object.entityPos, -32, -56, 32, 56, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
				if checkResult == 1
					object[currentPlayer].ypos += 0x20000
				end if
			next
			object.ypos += 0x20000
		else
			foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
				BoxCollisionTest(C_BOX, object.entityPos, -32, -56, 32, 56, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			next
			object.state++
		end if
		break
	case 2
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_BOX, object.entityPos, -32, -56, 32, 56, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		next
		break
	end switch
	object.angle = oscillation
	object.angle <<= 1
	Sin(object.value2, object.angle)
	object.value2 <<= 12
	object.value2 += object.ypos
	object.value2 &= -0x10000
	if object.outOfBounds == 1
		temp0 = object.ypos
		object.ypos = object.value1
		if object.outOfBounds == 1
			object.priority = PRIORITY_ACTIVE_BOUNDS
			object.state = 0
			object.value0 = 0
		else
			object.ypos = temp0
		end if
	end if
end event


event ObjectDraw
	DrawSprite(0)
	DrawSpriteXY(1, object.xpos, object.value2)
end event


event ObjectStartup
	LoadSpriteSheet("MZ/Objects.gif")
	SpriteFrame(-32, -56, 64, 112, 126, 1)
	SpriteFrame(-16, -16, 31, 32, 159, 114)
	foreach (TypeName[Button Pillar], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].value1 = object[arrayPos0].ypos
	next
	SetTableValue(TypeName[Button Pillar], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(ButtonPillar_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(ButtonPillar_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
